package com.kgcx.schedule.service;

import com.kgcx.common.client.organization.pojo.Driver;
import com.kgcx.common.constant.Cons;
import com.kgcx.schedule.domain.ScheduleRecordDomain;
import com.kgcx.schedule.domain.ScheduleReserveCfgDetailDomain;
import com.kgcx.schedule.model.ScheduleException;

import java.util.List;

/**
 * 立即类订单派车
 *
 * @author 袁进勇
 */
public abstract class ScheduleOrderNowService extends ScheduleOrderService {
    // private static final Logger LOG = LoggerFactory.getLogger(ScheduleOrderNowService.class);

    protected List<Driver> driverList;


    @Override
    protected void prepareRecord(ScheduleRecordDomain record) {
        super.prepareRecord(record);

        record.setSchedule_task(Cons.BOOLEAN_FALSE); // 不需要定时任务来调度，立即调度
        record.setFisrt_schedule_time(record.getCreate_time()); // 立即类订单，取当前时间作为调度时间
        record.setLatest_schedule_time(record.getFisrt_schedule_time()); // 定时任务扫描时，根据最近派单时间来调度
    }

    @Override
    protected void checkRecord(ScheduleRecordDomain record, ScheduleReserveCfgDetailDomain cfgDetail)
            throws ScheduleException {
        driverList = getDriverList(record);
        checkReserveQuantity(record, cfgDetail, driverList.size());
    }

    @Override
    protected void afterRecordAdded(ScheduleRecordDomain record, ScheduleReserveCfgDetailDomain cfgDetail)
            throws ScheduleException {
        scheduleRecord(record, cfgDetail, driverList);
    }

}
